package com.ittao.taopicture.infrastructure.mapper;

import com.ittao.taopicture.domain.user.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author 86134
 * @description 针对表【user(用户)】的数据库操作Mapper
 * @createDate 2025-07-17 21:52:06
 * @Entity com.ittao.taopicture.domain.user.entity.User
 */
public interface UserMapper extends BaseMapper<User> {

    /**
     * 忽略逻辑删除查询用户（包括已删除的用户）
     * 用于用户注册时检查账号是否存在
     *
     * @param userAccount 用户账号
     * @return 用户信息（可能是已删除的用户）
     */
    @Select("SELECT id, userAccount, userPassword, userName, userAvatar, userProfile, userRole, " +
            "editTime, createTime, updateTime, isDelete " +
            "FROM user WHERE userAccount = #{userAccount}")
    User selectIgnoreLogicDelete(@Param("userAccount") String userAccount);

    /**
     * 忽略逻辑删除状态，强制更新用户信息
     * 用于恢复已删除用户的注册
     *
     * @param user 用户信息
     * @return 更新的记录数
     */
    @Update("UPDATE user SET userPassword = #{userPassword}, userName = #{userName}, " +
            "userRole = #{userRole}, isDelete = #{isDelete}, updateTime = NOW() " +
            "WHERE id = #{id}")
    int updateIgnoreLogicDelete(User user);
}
